<template>
    <base-breadcrumb>
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card :bordered="false">
            <list-table
                ref="table"
                :columns="columns"
                :request="loadData"
            >
                <template slot="prefix" slot-scope="ref">
                    <a-button v-btn-permission="'lu_009_add_01'" type="primary" icon="plus"
                              @click="$nav('add')">新增
                    </a-button>
                </template>
                <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
                <template slot="activityTime" slot-scope="text, record, index">
                    {{ record.activityTime|dateFormat }}
                </template>
                <template slot="operation" slot-scope="text, record, index">
                    <MoreButton>
                        <a v-btn-permission="'lu_009_loo_04'" @click="$nav('add',{id:record.id,detail:1})">查看</a>
                        <!--                        <span v-if="record.reviewAuditStatus === 'DRAFT' || record.reviewAuditStatus === 'REJECTED'"-->
                        <!--                                                          @click="handleEdit(record, 1)">编辑</span>-->
                        <a v-btn-permission="'lu_009_edi_02'" @click="$nav('add',{id:record.id})">编辑</a>
                        <a v-btn-permission="'lu_009_del_03'" v-if="record.auditStatus !== 'PAST'"
                              @click="handleDel(record.id)">删除</a>
                    </MoreButton>
                </template>
            </list-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import sanSaiActivityLog from '@/api/union/sanSaiActivityLog.js'
import SelectTreeUnion from '@/components/Select/SelectTreeUnion'

export default {
    name:'a'+Date.now(),

    comments: {
        SelectTreeUnion
    },
    data() {
        return {
            columns: [
                {
                    title: '序号',
                    dataIndex: 'index',
                    width: 70,
                    scopedSlots: { customRender: 'index' }
                }, {
                    title: '活动主题',
                    dataIndex: 'activityTheme',
                    width: 150
                },
                {
                    title: '活动类型',
                    dataIndex: 'activityType',
                    width: 150
                },
                {
                    title: '层级',
                    dataIndex: 'levelName',
                    width: 150
                },
                {
                    title: '工会组织',
                    dataIndex: 'orgName',
                    width: 120
                },
                {
                    title: '活动时间',
                    dataIndex: 'activityTime',
                    scopedSlots: { customRender: 'activityTime' },
                    width: 150
                },
                {
                    title: '活动地点',
                    dataIndex: 'activityAddress',
                    width: 150
                },
                {
                    title: '操作',
                    width: 200,
                    fixed: 'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            searchArr: [
                {
                    name: '活动主题',
                    type: 'input',
                    value: 'activityTheme'
                },

                {
                    name: '活动类型',
                    type: 'select',
                    value: 'activityType',
                    data: [
                        { label: '铁军杯劳动竞赛', value: '铁军杯劳动竞赛' },
                        { label: '安康杯竞赛', value: '安康杯竞赛' },
                        { label: '职工技能竞赛', value: '职工技能竞赛' }
                    ]
                },
                {
                    name: '层级',
                    type: 'select',
                    value: 'level',
                    data: []
                },
                {
                    name: '工会组织',
                    type: SelectTreeUnion,
                    valueKey: 'orgId',
                },
                {
                    name: '活动时间',
                    type: 'dateRangeFormatx',
                    value: 'activityTime'
                }
            ],
            loadData: (params) => {
                return sanSaiActivityLog.getPageActivityRecord(Object.assign(params, { query: this.queryParam }))
            },
            queryParam: {}
        }
    },
    created() {
        this.getTypeLabel({ type: 1 })
    },
    methods: {
        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleDel(id) {
            this.$delList3(sanSaiActivityLog.deleteByPrimaryKey, () => {
                this.search()
            }, { id })
        },
        async getTypeLabel(args) {
            const { unionApiUrl } = require('@/api/config.js')
            const Union = require('@/api/union').default
            const { getLabels } = new Union(unionApiUrl, 'queryTypesLabelList')
            let res = await getLabels(args)
            this.searchArr[2].data = res.data ? res.data : []
            this.searchArr[2].data = this.searchArr[2].data.map(v => {
                return { label: v.name, value: v.id }
            })
        }
    }
}
</script>
